package com.itheima.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.CheckltemMapper;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.R;
import com.itheima.service.CheckitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class CheckitemServiceImpl implements CheckitemService {
    @Autowired
    private CheckltemMapper checkltemMapper;

    @Override
    public HashMap<String, Object> findPage(PageBean pageBean) {
        Integer currentPage = pageBean.getCurrentPage();
        Integer pageSize = pageBean.getPageSize();
        String queryString = pageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);
        if (queryString != null){
            queryString = "%" + queryString + "%";
        }
        List<CheckItem> list = checkltemMapper.getlist( queryString);
        PageInfo<CheckItem> pageInfo = new PageInfo<CheckItem>(list);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public R addcheckItem(CheckItem checkItem) {
        checkltemMapper.add(checkItem);
        R r = new R();
        r.setFlag(true);
        r.setMessage("新增检查项成功");
        return r;
    }

    @Override
    public R delete(String id) {
        checkltemMapper.deleteById(id);
        R r = new R();
        r.setFlag(true);
        r.setMessage("删除检查项成功");
        return r;
    }

    @Override
    public R getById(String id) {
        CheckItem checkItem = checkltemMapper.getById(id);
        R r = new R();
        r.setFlag(true);
        r.setMessage("查询检查项成功");
        r.setData(checkItem);
        return r;
    }

    @Override
    public R updateById(CheckItem checkItem) {
        checkltemMapper.updateById(checkItem);
        R r = new R();
        r.setFlag(true);
        r.setMessage("编辑会员成功");
        return r;
    }
}
